package com.broada.apm.entity;

import java.util.HashMap;
import java.util.Map;

import com.broada.apm.indicator.api.model.Variable;
import com.broada.apm.util.SettingMapConstants;

public class ConfigVariable {
	private int alarmType;
	private int confType;
	private String apdex_t;
	private String machineName;
	private String localIp;
	private String subnetMask;
	private String gateway;
	private String firstDNS;
	private String secondDNS;
	private String autoSync;
	private String webPort;
	private String apmServerEnable;
	private String remoteIp;
	private String timeServer;
	private String port;
	private String defaultpolicy;
	private String policyRules;
	private String snmpOn;
	private String snmpIp;
	private String snmpPort;
	private String isDedicate;
	private String isUpdate;
	private String cleanTime;

	private String resetToFactory;

	public ConfigVariable() {
		super();
	}

	public ConfigVariable(int confType) {
		super();
		this.confType = confType;
	}

	public int getAlarmType() {
		return alarmType;
	}

	public void setAlarmType(int alarmType) {
		this.alarmType = alarmType;
	}

	public int getConfType() {
		return confType;
	}

	public void setConfType(int confType) {
		this.confType = confType;
	}

	public String getApdex_t() {
		return apdex_t;
	}

	public void setApdex_t(String apdex_t) {
		this.apdex_t = apdex_t;
	}

	public String getMachineName() {
		return machineName;
	}

	public void setMachineName(String machineName) {
		this.machineName = machineName;
	}

	public String getLocalIp() {
		return localIp;
	}

	public void setLocalIp(String localIp) {
		this.localIp = localIp;
	}

	public String getSubnetMask() {
		return subnetMask;
	}

	public void setSubnetMask(String subnetMask) {
		this.subnetMask = subnetMask;
	}

	public String getGateway() {
		return gateway;
	}

	public void setGateway(String gateway) {
		this.gateway = gateway;
	}

	public String getFirstDNS() {
		return firstDNS;
	}

	public void setFirstDNS(String firstDNS) {
		this.firstDNS = firstDNS;
	}

	public String getSecondDNS() {
		return secondDNS;
	}

	public void setSecondDNS(String secondDNS) {
		this.secondDNS = secondDNS;
	}

	public String getAutoSync() {
		return autoSync;
	}

	public void setAutoSync(String autoSync) {
		this.autoSync = autoSync;
	}

	public String getWebPort() {
		return webPort;
	}

	public void setWebPort(String webPort) {
		this.webPort = webPort;
	}

	public String getApmServerEnable() {
		return apmServerEnable;
	}

	public void setApmServerEnable(String apmServerEnable) {
		this.apmServerEnable = apmServerEnable;
	}

	public String getRemoteIp() {
		return remoteIp;
	}

	public void setRemoteIp(String remoteIp) {
		this.remoteIp = remoteIp;
	}

	public String getTimeServer() {
		return timeServer;
	}

	public void setTimeServer(String timeServer) {
		this.timeServer = timeServer;
	}

	public String getPort() {
		return port;
	}

	public void setPort(String port) {
		this.port = port;
	}

	public String getDefaultpolicy() {
		return defaultpolicy;
	}

	public void setDefaultpolicy(String defaultpolicy) {
		this.defaultpolicy = defaultpolicy;
	}

	public String getPolicyRules() {
		return policyRules;
	}

	public void setPolicyRules(String policyRules) {
		this.policyRules = policyRules;
	}

	public String getSnmpOn() {
		return snmpOn;
	}

	public void setSnmpOn(String snmpOn) {
		this.snmpOn = snmpOn;
	}

	public String getSnmpIp() {
		return snmpIp;
	}

	public void setSnmpIp(String snmpIp) {
		this.snmpIp = snmpIp;
	}

	public String getSnmpPort() {
		return snmpPort;
	}

	public void setSnmpPort(String snmpPort) {
		this.snmpPort = snmpPort;
	}

	public String getIsDedicate() {
		return isDedicate;
	}

	public void setIsDedicate(String isDedicate) {
		this.isDedicate = isDedicate;
	}

	public String getIsUpdate() {
		return isUpdate;
	}

	public void setIsUpdate(String isUpdate) {
		this.isUpdate = isUpdate;
	}

	public String getCleanTime() {
		return cleanTime;
	}

	public void setCleanTime(String cleanTime) {
		this.cleanTime = cleanTime;
	}

	public String getResetToFactory() {
		return resetToFactory;
	}

	public void setResetToFactory(String resetToFactory) {
		this.resetToFactory = resetToFactory;
	}

	/**
	 * @param web前端传过来的带有配置值的map
	 * @param confType 配置类型标识值
	 * @return 保存方法参数所需map类型
	 */
	public Variable[] getConfData() {
		Variable[] confVar = null;
		switch (confType) {
		// 1,基本配置;2,集成配置;3,服务器配置;4,数据包过滤规则;5,全局告警配置;6,地理位置信息配置;7,L7模块;8,用户管理;
		// 9,集群配置;10,历史数据管理;11,日志分析;12,系统监控;13,配置管理;14,系统升级;
		case 1:
			confVar = new Variable[1];
			Variable varApdex = confVar("basic.apdex_t", apdex_t);
			// Variable varKeeptime=confVar("basic.keep_time",keepTime);
			confVar[0] = varApdex;
			// confVar[1]=varKeeptime;
			break;
		// case 2:
		// confVar=new Variable[7];
		// Variable varCossEnable=confVar("integrate.coss.enabled",cossEnable);
		// Variable varCossIp = confVar("integrate.coss.ip",cossIp);
		// Variable varCossPort = confVar("integrate.coss.port",cossPort);
		// Variable varAlarmEnable=confVar("integrate.alert.trap_enabled",alarmEnable);
		// Variable varAlarmIp = confVar("integrate.alert.ip",alarmIp);
		// Variable varAlarmPort = confVar("integrate.alert.port",alarmPort);
		// Variable varCertificationEnable = confVar("integrate.sso.enabled",certificationEnable);
		// confVar[0]=varCossEnable;
		// confVar[1]=varCossIp;
		// confVar[2]=varCossPort;
		// confVar[3]=varAlarmEnable;
		// confVar[4]=varAlarmIp;
		// confVar[5]=varAlarmPort;
		// confVar[6]=varCertificationEnable;
		// break;
		case 3:
			confVar = new Variable[12];
			Variable varMachineName = confVar("server.basic.host_name", machineName);
			Variable varLocalIp = confVar("server.basic.ip", localIp);
			Variable varSubnetMask = confVar("server.basic.netmask", subnetMask);
			Variable varGateway = confVar("server.basic.gateway", gateway);
			Variable varFirstDNS = confVar("server.basic.dns1", firstDNS);
			Variable varSecondDNS = confVar("server.basic.dns2", secondDNS);
			Variable varAutoSync = confVar("server.time.auto_sync", autoSync);
			Variable varWebPort = confVar("service.web.port", webPort);
			Variable varApmServerEnable = confVar("service.indicator.enabled", apmServerEnable);
			Variable varRemoteIp = confVar("service.indicator.remote_ip", remoteIp);
			Variable varTimeServer = confVar("server.time.ntp_server", timeServer);
			Variable varPort = confVar("service.indicator.remote_port", port);
			confVar[0] = varMachineName;
			confVar[1] = varLocalIp;
			confVar[2] = varSubnetMask;
			confVar[3] = varGateway;
			confVar[4] = varFirstDNS;
			confVar[5] = varSecondDNS;
			confVar[6] = varAutoSync;
			confVar[7] = varWebPort;
			confVar[8] = varApmServerEnable;
			confVar[9] = varRemoteIp;
			confVar[10] = varTimeServer;
			confVar[11] = varPort;
			break;
		case 4:
			confVar = new Variable[2];
			Variable varDefaultpolicys = confVar("filter.default_policy", defaultpolicy);
			Variable varPolicyRules = confVar("filter.rules", policyRules);
			confVar[0] = varDefaultpolicys;
			confVar[1] = varPolicyRules;
			break;
		case 5:
			confVar = new Variable[3];
			Variable varSnmpOn = confVar("integrate.alert.trap_enabled", snmpOn);
			Variable varSnmpIp = confVar("integrate.alert.ip", snmpIp);
			Variable varSnmpPort = confVar("integrate.alert.port", snmpPort);
			confVar[0] = varSnmpOn;
			confVar[1] = varSnmpIp;
			confVar[2] = varSnmpPort;
			break;
		case 6:
			confVar = new Variable[2];
			Variable varIsuse = confVar("map.internal.enabled", isDedicate);
			Variable varIsUpdate = confVar("map.internal.auto_sync", isUpdate);
			// Variable varMapType = confVar("map.to_use",mapType);
			confVar[0] = varIsuse;
			confVar[1] = varIsUpdate;
			// confVar[1]=varMapType;
			break;
		case 10:
			confVar = new Variable[1];
			Variable varCleanTime = confVar("history.cleantime", cleanTime);
			confVar[0] = varCleanTime;
			break;
		}
		return confVar;
	}

	/**
	 * @param confKey 为es中要修改字段的key
	 * @param confValue 前台传过来的值
	 * @return
	 */
	public Variable confVar(String confKey, String confValue) {
		Map<String, Object> map = new HashMap<String, Object>();
		if (confValue != null && confValue != "") {
			map.put("value", confValue);
		} else {
			map.put("value", "");
		}
		return Variable.newBuilder().setId(SettingMapConstants.SETTINGSMAP.get(confKey)).setItem(map);
	}
	
	public String getSettingKey(String id) {
		for (Map.Entry<String, String> entry : SettingMapConstants.SETTINGSMAP.entrySet()) {
			if(entry.getValue().equals(id)) {
				return entry.getKey();
			}
		}
		return null;
	}
}
